package leetcode.util;

import java.util.Arrays;

public class Utils {
    /*

按层叠放的二叉树元素数组存在 <br>起点为0，且当前节点为i,则左二子为2i+1,右儿子为2i+2</br>
 */
    public static TreeNode buildTree(Integer... nums) {
        if (nums.length < 0) return null;
        TreeNode head = buildNode(0, nums);
        return head;
    }

    private static TreeNode buildNode(Integer currentIndex, Integer... nums) {
        TreeNode currentNode = null;
        if (currentIndex < nums.length) {
            if (nums[currentIndex] == null) {
                return currentNode;
            }
            currentNode = new TreeNode(nums[currentIndex]);
            currentNode.left = buildNode(2 * currentIndex + 1, nums);
            currentNode.right = buildNode(2 * currentIndex + 2, nums);
        }
        return currentNode;
    }

    public static int[] toArray(int...nums){
        return nums;
    }
}
